package com.applet.controller;

import com.applet.Base.BaseController;
import com.applet.annotation.SystemControllerLog;
import com.applet.entity.request.*;
import com.applet.entity.response.UserResponse;
import com.applet.service.UserService;
import com.applet.utils.AppletResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Api(value="用户controller",tags={"用户操作接口"})
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

    @ApiOperation(value="打开App传数据(未完成)")
    @SystemControllerLog(funcionExplain = "打开App传数据")
    @PostMapping(value = "/open")
    public AppletResult open(@RequestBody OpenRequest openRequest){
        return userService.open(openRequest);
    }

    @ApiOperation(value="发送验证码")
    @SystemControllerLog(funcionExplain = "发送验证码")
    @PostMapping(value = "/verificationCode")
    public AppletResult sendVerificationCode(HttpServletRequest request,
                                             @RequestBody VerificationCodeRequest verificationCodeRequest){
        verificationCodeRequest = (VerificationCodeRequest) headUtil.getAllReqHead(request,verificationCodeRequest);
        return userService.sendVerificationCode(verificationCodeRequest);
    }

    @ApiOperation(value="用户注册")
    @SystemControllerLog(funcionExplain = "用户注册")
    @PostMapping(value = "/register")
    public AppletResult register(HttpServletRequest request,
                                 @RequestBody RegisterRequest registerRequest){
        registerRequest = (RegisterRequest) headUtil.getAllReqHead(request,registerRequest);
        return userService.register(registerRequest);
    }

    @ApiOperation(value="用户登陆")
    @SystemControllerLog(funcionExplain = "用户登陆")
    @PostMapping(value = "/login")
    public AppletResult<UserResponse> login(HttpServletRequest request,
                                            @RequestBody LoginRequest loginRequest){
        loginRequest = (LoginRequest) headUtil.getAllReqHead(request,loginRequest);
        return userService.login(loginRequest);
    }

    @ApiOperation(value="用户退出登陆")
    @SystemControllerLog(funcionExplain = "用户退出登陆")
    @PostMapping(value = "/loginOut")
    public AppletResult loginOut(HttpServletRequest request,
                                 @RequestBody LoginOutRequest loginOutRequest){
        loginOutRequest = (LoginOutRequest) headUtil.getAllReqHead(request,loginOutRequest);
        return userService.loginOut(loginOutRequest);
    }

    @ApiOperation(value="修改昵称")
    @SystemControllerLog(funcionExplain = "修改昵称")
    @PostMapping(value = "/modify/nickName")
    public AppletResult<UserResponse> modifyNickName(HttpServletRequest request,
                                       @RequestBody ModifyNickNameRequest modifyNickNameRequest){
        modifyNickNameRequest = (ModifyNickNameRequest) headUtil.getAllReqHead(request,modifyNickNameRequest);
        return userService.modifyNickName(modifyNickNameRequest);
    }

    @ApiOperation(value="验证旧手机和新手机号")
    @SystemControllerLog(funcionExplain = "验证旧手机和新手机号")
    @PostMapping(value = "/modify/phone")
    public AppletResult<UserResponse> modifyPhone(HttpServletRequest request,
                                    @RequestBody ModifyPhoneRequest modifyPhoneRequest){
        modifyPhoneRequest = (ModifyPhoneRequest) headUtil.getAllReqHead(request,modifyPhoneRequest);
        return userService.modifyPhone(modifyPhoneRequest);
    }

}
